/*
 * @Author: your name
 * @Date: 2021-03-28 09:51:05
 * @LastEditTime: 2021-04-02 13:24:15
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \my-app-koa\models\User.js
 */
const mongoose = require('mongoose');
const Schema = mongoose.Schema;

// 实例化数据模板
const PostSchema = new Schema({
  user: {
    type: String,
    ref: 'users',
    require: true
  },
  text: {
    type: String,
    required: true
  },
  likes: [
    {
      user: {
        type: Schema.Types.ObjectId
      }
    }
  ],
  comments: [
    {
      user: {
        type: Schema.Types.ObjectId
      },
      text: {
        type: String,
        required: true
      },
      date: {
        type: Date,
        default: Date.now

      }
    }
  ],
  name: {
    type: String,
  },
  avatar: {
    type: String
  },
  date: {
    type: Date,
    default: Date.now

  }
})


module.exports = Post = mongoose.model("post", PostSchema)